/* File parser.mly */

/* The Header */
%{
open Syntax
%}

/* The Grammar */
%token <int> TokenInt
%token <string> TokenProp
%token TokenT
%token TokenF
%token TokenNot
%token TokenAnd
%token TokenOr
%token TokenImp
%token TokenEq
%token TokenNeq
%token TokenNewLine
%token TokenEnd
%token TokenEof

/* highest precedence */
/* lowest precedence */


%start main             /* the entry point */
%type <Syntax.gba> main

%%

main:
   TokenInt TokenInt states TokenEof      { ($1, $2, $3) }
;

states:
														{ [] }
	| state states									{ ($1)::$2 }
;

state:
	TokenInt TokenInt final_sets transitions		{ ($1, $2, $3, $4) }
;

final_sets:
	TokenEnd											{ [] }
	| TokenInt final_sets						{ ($1)::$2 }
;

transitions:
	TokenEnd											{ [] }
	| TokenInt gate transitions            { ($1, $2)::$3 }
;

gate:
	TokenT											{ True }
	| TokenF											{ False }
	| TokenProp 									{ Prop $1 }
	| TokenNot gate								{ Not $2 }
	| TokenAnd gate gate							{ And ($2, $3) }
	| TokenOr gate gate							{ Or ($2, $3) }
	| TokenImp gate gate							{ Imp ($2, $3) }
	| TokenEq gate gate							{ Eq ($2, $3) }
	| TokenNeq gate gate							{ Neq ($2, $3) }
;;
